package org.nobject.common.lang;

import java.util.HashMap;
import java.util.Map;

public class ThreadUtils {

	/** 当前线程线程变量池 */
	private static ThreadLocal tlContext = new ThreadLocal();
	
	public static void put(Object key,Object value){
		Map m=(Map)tlContext.get();
		if(m==null){
			m=new HashMap();
			tlContext.set(m);
		}
		m.put(key, value);
	}
	
	public static Object get(Object key){
		Map m=(Map)tlContext.get();
		if(m==null) return null;
		return m.get(key);
	}
	
	public static void clear(Object key){
		Map m=(Map)tlContext.get();
		if(m==null) return;
		m.remove(key);
	}
	
	/** 
	 * 是否含有指定Key
	 * @param key
	 * @return
	 */
	public static boolean contains(Object key){
		Map m=(Map)tlContext.get();
		if(m==null) return false;
		return m.containsKey(key);
	}
}
